﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Xml.Serialization;


namespace VoiceTestPlatform
{
    [XmlRoot("ProjectItem")]
    public class ProjectItem : NotifyObject
    {
        public ProjectItem()
        {

        }
        public ProjectItem(Sound sound)
        {
            if (sound == null)
            {
                throw new ArgumentException("sound can't be null");
            }
            //this.sound = sound;
            this.DisplayText = sound.DisplayText;
            this.Path = sound.Path;
            var te = DisplayText.Split('_');
            if (te == null ||te.Length != 4)
            {
                MessageBox.Show("音频命名格式错误\n\r正确音频命名为:\n\r地域_性别_编号_命令.wav\n\r示例：广东_男声_4_美的电饭煲.wav\n\r错误命名会使程序出错!!!");
            }
        }



        private int playTimes;
        [XmlAttribute("PlayTimes")]
        public int PlayTimes
        {
            get { return playTimes; }
            set { playTimes = value; RaisePropertyChanged("PlayTimes"); }
        }

        private bool isLoop;
        [XmlAttribute("IsLoop")]
        public bool IsLoop
        {
            get { return isLoop; }
            set
            {
                isLoop = value;
                RaisePropertyChanged("IsLoop");
                RaisePropertyChanged("LoopText");
            }
        }
        [XmlIgnore]
        public string LoopText
        {
            get { return IsLoop ? "是" : "否"; }

        }

        private string path;
        [XmlAttribute("Path")]
        public string Path
        {
            get { return path; }
            set { path = value; RaisePropertyChanged("Path"); }
        }

        private string displayText;
        [XmlAttribute("DisplayText")]
        public string DisplayText
        {
            get { return displayText; }
            set { displayText = value; RaisePropertyChanged("DisplayText"); }
        }

         [XmlIgnore]
        public string AudioCommand
        {
            get
            {   
                // 正确音频命名为 地方_性别_序列_命令.wav

               // Application.Current.Dispatcher.BeginInvoke(new Action(() => { Application.Current.MainWindow.Title = "我修改过的窗体标题"; }));
                var te = DisplayText.Split('_');
                if (te.Length >0)
                {
                    var r = te[te.Length -1].Split('.');
                    if (r.Length > 0)
                    {
                        return r[0];
                    }
                }
                return string.Empty;

            }
        }

         [XmlIgnore]
         public string AudioArea //地域
         {
             get
             {
                
                 var te = DisplayText.Split('_');
                 if (te.Length == 4)
                 {
                     return te[0];
                     
                 }
                 return string.Empty;

             }
         }

         [XmlIgnore]
         public string AudioSex //性别
         {
             get
             {

                 var te = DisplayText.Split('_');
                 if (te.Length == 4)
                 {
                     return  te[1];

                 }
                 return string.Empty;

             }
         }

         [XmlIgnore]
         public string AudioNo //编号
         {
             get
             {

                 var te = DisplayText.Split('_');
                 if (te.Length == 4)
                 {
                     return  te[2];

                 }
                 return string.Empty;

             }
         }

         [XmlIgnore]
         public string Sex //性别
         {
             get
             {

                 var te = DisplayText.Split('_');
                 if (te.Length == 4)
                 {
                     var r = te[1].Split('.');

                 }
                 return string.Empty;

             }
         }

        private bool isPlaying = false;
        [XmlIgnore]
        public bool IsPlaying
        {
            get { return isPlaying; }
            set { isPlaying = value; RaisePropertyChanged("IsPlaying"); }
        }

        public override string ToString()
        {
            return this.DisplayText;
        }

    }
}
